Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
ionic geolocation plugin error: "No provider for Geolocation"

I'm trying to use geolocation in my ionic2 hello world project, and I add the ionic plugin "Geolocation" following the instruction on the official site.

I've run these two commands:

$ ionic plugin add cordova-plugin-geolocation
$ npm install --save @ionic-native/geolocation

And this is my home.ts:

import { Component } from '@angular/core';
import {Geolocation} from '@ionic-native/geolocation'
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  map:any=null;
  geoInfo:any={
      resp:'',
      data:''
  };

  constructor(
      public navCtrl: NavController,
      private geolocation: Geolocation
  ) {

  }

  test(){
      this.geolocation.getCurrentPosition().then((resp) => {
          this.geoInfo.resp=JSON.stringify(resp);
          // resp.coords.latitude
          // resp.coords.longitude
      }).catch((error) => {
          console.log('Error getting location', error);
          this.geoInfo.resp='Error getting location';
      });

      let watch = this.geolocation.watchPosition();
      watch.subscribe((data) => {
          this.geoInfo.data=JSON.stringify(data);
          // data can be a set of coordinates, or an error (if an error occurred).
          // data.coords.latitude
          // data.coords.longitude
      });

  }

}

However, I got the following error in my chrome's console:

EXCEPTION: Error in ./TabsPage class TabsPage - inline template:0:0 caused by: No provider for Geolocation!
error_handler.js:56ORIGINAL EXCEPTION: No provider for Geolocation!

screenshot

At first I thought it was because I was debugging in browser, but then I got then same error in my Android phone.

So what does "No provider for Geolocation" mean and how should I use geolocation in my ionic2 project?

Thanks a lot!

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You need to add the provider to the NgModule, i.e module.ts under providers,

providers: [
  Geolocation
]
about 4 years ago · Santiago Trujillo Report

0

You need to import the Geolocation class and add it to your list of providers in the app.module.ts file

import { Geolocation } from '@ionic-native/geolocation';

providers: [
     Geolocation
]
about 4 years ago · Santiago Trujillo Report

0

For Ionic 4 you add to app.module.ts top:

import { Geolocation } from '@ionic-native/geolocation/ngx';

And on the bottom, inside of the Providers array, add Geolocation:

providers: [
    Geolocation,
    ...
]
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!